package com.yequan.thread.keyword.volatileword;

/**
 * @author : Administrator
 * @date : 2020/5/17
 */
public class VolatileFeatureExample1 {

    volatile long v1 = 0L;

    public void set(long l) {
        v1 = l;
    }

    public void getAndIncrement() {
        v1++;
    }

    public long get() {
        return v1;
    }

    public static void main(String[] args) {
        VolatileFeatureExample1 volatileFeatureExample1 = new VolatileFeatureExample1();
        Thread thread1 = new Thread(() -> volatileFeatureExample1.set(1));
        Thread thread2 = new Thread(() -> volatileFeatureExample1.getAndIncrement());
        Thread thread3 = new Thread(() -> System.out.println(volatileFeatureExample1.get()));

        thread1.start();
        thread3.start();
        thread2.start();
    }

}
